package com.frank.demo.util;

/**
 * 懒汉式
 * Created by zhy on 2018/6/14.
 */
public class Singleton {

    private static Singleton singleton;

    private Singleton() {
    }

    //双重检查
    public static Singleton getInstance() {
        if (singleton == null) {
            synchronized (Singleton.class) {
                if (singleton == null) {
                    return new Singleton();
                }
            }
        }
        return singleton;
    }


    //静态内部类法
    private static class LazyHolder {
        private static final Singleton INSTANCE = new Singleton();
    }
    public static final Singleton getInstance2() {
        return LazyHolder.INSTANCE;
    }



}